package org.wutopia.labcloud.test.demo;


import org.springframework.http.server.PathContainer;
import org.springframework.web.util.pattern.PathPattern;
import org.springframework.web.util.pattern.PathPatternParser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {

    public static void main(String[] args) {
//        String path = "/user/122352346233";
//        Pattern pattern = Pattern.compile("^/user/([\\d]+)$");
//        Matcher matcher = pattern.matcher(path);
//        if (matcher.find()) {
//            String id = matcher.group(1); // 提取ID：abc123
//            System.out.println(id);
//        }

        PathPatternParser parser = new PathPatternParser();
        PathPattern pattern = parser.parse("/api/users/{id}"); // 解析模式
        PathContainer path = PathContainer.parsePath("/api/users/123"); // 解析请求路径

        boolean isMatch = pattern.matches(path); // 检查是否匹配 → true
        System.out.println("是否匹配" + isMatch);
        PathPattern.PathMatchInfo variables = pattern.matchAndExtract(path); // 提取路径变量
        String id = variables.getUriVariables().get("id");

        System.out.println("获取id: " + id);
    }
}
